import requests
import base64
import time
import json

url = "http://localhost:5001/sendTextMsgToPerson"

# 用户Auth——测试示例
auth = str(base64.b64encode(f'admin:123456'.encode('utf-8')), 'utf-8')
print('auth', auth)

# 发送钉钉个人消息——测试示例
content = {
    "dingtalk_agent_id": 804578772,
    "dingtalk_app_key": "dingkwmfrbsv0cencgb9",
    "dingtalk_app_secret": "_OVByoifueYAH0X6mAQjleWfgFhB0cfZ3v4MNgAHrfjYG-a_u4ULXbN9ujdpoVOe",
    "dingtalk_userid_list": [
        "023405250820658815"
    ],
    "dingtalk_content": f"这里Text内容{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}"
}
headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Basic {auth}'
}
res = requests.post(url, data=json.dumps(content), headers=headers)
print(res.text)
